package cn.apotato.inclusion.handler;

import cn.apotato.inclusion.commin.response.Message;
import cn.apotato.inclusion.commin.response.ResponseData;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * 全局异常处理
 * Created with IntelliJ IDEA.
 *
 * 注意：@RestController和@ControllerAdvice必须都要添加不然不会生效
 * @author : xphu
 * @date : 2021-12-10 10:20
 */
@RestController
@ControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(RuntimeException.class)
    public Message exceptionHandler(RuntimeException e){
        System.out.println("程序出现异常了！原因是:"+e.getMessage());
        return ResponseData.fail(e.getMessage()).dateTime().build();
    }
}
